﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Net;

namespace WinSat
{
    public class NetTools
    {
        [DllImport("wininet.dll")]
        private static extern bool InternetGetConnectedState(ref uint flags, uint dwReserved);

        public bool IsConnected
        {
            get
            {
                uint flags = 0;
                return InternetGetConnectedState(ref flags, 0);
            }
        }

        public bool IsConnected2
        {
            get
            {
                try
                {
                    string hostName = Dns.GetHostName();
                    IPHostEntry curHost = Dns.GetHostEntry(Program.Session[ Settings.Sunucu].ToString());
                    return curHost.AddressList[0].ToString() != IPAddress.Loopback.ToString();
                }
                catch
                {
                    return false;
                }
            }
        }
    }
}
